package com.cskt.erptemplate.pojo.result;

import java.io.Serializable;

/**
 * @Author 陈厚德
 * @Version 2.2
 */
public class Result<T> implements Serializable {

    private  String msg ;
    private  String code ;
    private  T data ;

    private Result(String code, String msg) {
        this.msg = msg;
        this.code = code;
    }

    //带返回的数据
    public  static  <T> Result<T> ok(T data){

        return  new Result<T>("200","操作成功",data);

    }

    public  static  <T> Result<T> ok(){

//        return  new Result<>("200","操作成功");
        return  ok(null);

    }

//，默认出错
    public  static  <T> Result<T> error(){
        return  error(ResultEnum.ERROR);
    }

    public  static  <T> Result<T> error(ResultEnum resultEnum){
        return  new Result<T>(resultEnum.getCode(), resultEnum.getMsg());
    }

    public  static  <T> Result<T> error(String code, String msg){
        return  new Result<T>(code,msg);
    }




    private Result() {
    }

    private Result(String code, String msg, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 获取
     * @return msg
     */



    public String toString() {
        return "Result{msg = " + msg + ", code = " + code + ", data = " + data + "}";
    }
}
